<template>
  <div class="h-full">
    <SearchContainer @search="getData" @reset="getTime()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :colon="false" :label-col="{ style: { width: '80px' } }">
        <a-form-item name="dateRange" label="日期范围">
          <a-range-picker v-model:value="formState.dateRange" :default-value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <BaseTable column-code="000083" fill :data-source="tableData" bordered :loading="loading" :pagination="pagination">
        <template #bodyCell="{ column, index }">
          <template v-if="column.dataIndex == 'xh'">
            {{ index + 1 }}
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import dayjs from 'dayjs'
import { getSystemConfig } from '@/utils/systemConfig'

const formRef = ref(null)

const startTime = ref()
const endTime = ref()
const idDays = ref()
const formState = ref({ dateRange: [] })
const { loading, tableData, pagination, getData } = useTable({
  url: '/materials/psiform/getKcGysCertificateWarningList',
  formatParams: () => {
    return {
      stdate: formState.value.dateRange?.[0],
      eddate: formState.value.dateRange?.[1]
    }
  }
})
const getTime = () => {
  // CERTIFICATE_ALERT_DAYS:证书预警天数
  idDays.value = getSystemConfig('CERTIFICATE_ALERT_DAYS')
  startTime.value = idDays.value ? dayjs().format('YYYY-MM-DD') : dayjs().add(1, 'month').startOf('month').format('YYYY-MM-DD')
  endTime.value = idDays.value
    ? dayjs().add(getSystemConfig('CERTIFICATE_ALERT_DAYS'), 'days').format('YYYY-MM-DD')
    : dayjs().add(1, 'month').add(4, 'month').startOf('month').format('YYYY-MM-DD')
  formState.value.dateRange[0] = startTime.value
  formState.value.dateRange[1] = endTime.value
}

onMounted(async () => {
  getTime()
  await getData()
})
</script>

<style lang="less" scoped></style>
